package com.sokal.easycare.modules.forum.entity;

import java.util.List;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.google.common.collect.Lists;
import com.sokal.easycare.common.config.Global;
import com.sokal.easycare.common.persistence.DataEntity;
import com.sokal.easycare.common.utils.StringUtils;
import com.sokal.easycare.modules.sys.entity.MainUser;

/**
 * 论坛回帖Entity
 * @author lihaipei
 * @version 2017-05-07
 */
public class ForumReplies extends DataEntity<ForumReplies> {
	
	private static final long serialVersionUID = 1L;
	private String forumId;		// 论坛id
	private String content;		// 内容
	private String portFrom;		// 来自端口
	private Integer sort;		// 排序号-一般为回帖楼层
	private ForumReplies parent;		// 父级id-根据此id去判断是否为此回帖的回复
	private List<ForumReplies> replyingMsgList = Lists.newArrayList(); //获取子表（回复）列表
	private Boolean isTheLandlord; //是否为楼主 
	
	public ForumReplies() {
		super();
	}

	public ForumReplies(String id){
		super(id);
	}

	public ForumReplies(String forumId, ForumReplies parent){
		this.delFlag = DEL_FLAG_NORMAL;
		this.forumId = forumId;
		this.parent = parent;
	}

	@Length(min=0, max=64, message="论坛id长度必须介于 0 和 64 之间")
	public String getForumId() {
		return forumId;
	}

	public void setForumId(String forumId) {
		this.forumId = forumId;
	}
	
	@Length(min=0, max=1000, message="内容长度必须介于 0 和 1000 之间")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	@Length(min=0, max=100, message="来自端口长度必须介于 0 和 100 之间")
	public String getPortFrom() {
		return portFrom;
	}

	public void setPortFrom(String portFrom) {
		this.portFrom = portFrom;
	}
	
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}
	
	@JsonBackReference
	public ForumReplies getParent() {
		return parent;
	}

	public void setParent(ForumReplies parent) {
		this.parent = parent;
	}

	public List<ForumReplies> getReplyingMsgList() {
		return replyingMsgList;
	}

	public void setReplyingMsgList(List<ForumReplies> replyingMsgList) {
		this.replyingMsgList = replyingMsgList;
	}

	public Boolean getIsTheLandlord() {
		return isTheLandlord;
	}

	public void setIsTheLandlord(Boolean isTheLandlord) {
		this.isTheLandlord = isTheLandlord;
	}

	public MainUser getCreator() {
		if (createBy != null) {
			if (StringUtils.isNotBlank(createBy.getPortraitPhoto())) {
				if (!createBy.getPortraitPhoto().startsWith("http:")) {
					createBy.setPortraitPhoto(Global.getConfig("fastdfs_file_url")+createBy.getPortraitPhoto());
				}
			}
		}
		return createBy;
	}

}